/*
 * bundle文件上传alioss
 */
var path = require('path');
var config = require('./config');
var buildPath = config.alioss.buildPath;
var region = config.alioss.region;
var pre_path = config.alioss.pre_path;
var bucket = config.alioss.bucket;
var accessKeyId = config.alioss.accessKeyId;
var accessKeySecret = config.alioss.accessKeySecret;
var deleteAll = config.alioss.deleteAll;

// function fileType(name){
//   var type = '/ikanfan/pc/';
//   if(name.indexOf('css') != -1){
//     type += 'css/';
//   }else if(name.indexOf('js') != -1){
//     type += 'js/'
//   }else if(name.indexOf('gif') != -1 && !isNaN(name.split('.')[0])){
//     type += 'admin/emot/'
//   }else if(name.indexOf('png') != -1 && isNaN(name.split('.')[0])){
//     type += 'img/'
//   }else if(name.indexOf('gif') != -1 && isNaN(name.split('.')[0])){
//     type += 'img/'
//   }else if(name.indexOf('jpg') != -1 && isNaN(name.split('.')[0])){
//     type += 'img/'
//   }
//   return type
// }

var AliyunossWebpackPlugin = require('aliyunoss-webpack-plugin')
var oss = new AliyunossWebpackPlugin({
  buildPath: buildPath,
  region: region,
  accessKeyId: accessKeyId,
  accessKeySecret: accessKeySecret,
  bucket: bucket,
  deleteAll: deleteAll,
  generateObjectPath: function (filename) {
    return pre_path + '/' + filename
  },
  getObjectHeaders: function (filename) {
    return {
      Expires: 6000
    }
  }
});
oss.apply()